﻿//os

//top
#include "inc/gsf.h"

//mod
#include "zoom_lens.h"

#include "msg_func.h"

#include "spi_ms41929.h"



static void msg_func_zoom_lens(gsf_msg_t *req, int isize, gsf_msg_t *rsp, int *osize)
{
  rsp->err  = 0;
  rsp->size = 0;
  rsp->ch = req->ch;
  rsp->sid = req->sid;

  gsf_zoom_lens_t *lens = (gsf_zoom_lens_t*)req->data;
  switch(lens->cmd)
  {
    // case GSF_ZOOM_LENS_IRC:
    //   rsp->err = gsf_lens_ircut(req->ch, lens->arg1);
    //   break;
    case GSF_ZOOM_LENS_STOP:
      rsp->err = gsf_lens_stop(req->ch);
      break;
    case GSF_ZOOM_LENS_ZOOM:
      rsp->err = gsf_lens_zoom(req->ch, lens->arg1, lens->arg2);
      break;
    case GSF_ZOOM_LENS_FOCUS:
      rsp->err = gsf_lens_focus(req->ch, lens->arg1, lens->arg2);
      break;
    // case GSF_ZOOM_LENS_CAL:
    //   rsp->err = gsf_lens_cal(req->ch);
    //   break;
  }
  return;
}

static msg_func_t *msg_func[GSF_ID_ZOOM_LENS_END] = {
    [GSF_ID_MOD_CLI]      = NULL,
    [GSF_ID_ZOOM_LENS]   = msg_func_zoom_lens,
 };


int msg_func_proc(gsf_msg_t *req, int isize, gsf_msg_t *rsp, int *osize)
{
    if(req->id < 0 || req->id >= GSF_ID_ZOOM_LENS_END)
    {
        return FALSE;
    }
    
    if(msg_func[req->id] == NULL)
    {
        return FALSE;
    }   
    
    msg_func[req->id](req, isize, rsp, osize);
    
    return TRUE;
}
